package com.hy.service1;

import com.hy.service1.service.HelloServiceImpl;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class UserServiceApplication {
    public static void main(String[] args) throws TTransportException {
        new Thread(()->{thriftServiceStart();}).start();
        SpringApplication.run(UserServiceApplication.class, args);
    }

    public static void thriftServiceStart() {
        System.out.println("thrift服务端开启");
        TProcessor tProcessor = new HelloService.Processor<HelloService.Iface>(new HelloServiceImpl());
        TServerSocket tServerSocket = null;
        try {
            tServerSocket = new TServerSocket(9898);
        } catch (TTransportException e) {
            e.printStackTrace();
        }
        TServer.Args tArgs = new TServer.Args(tServerSocket);
        tArgs.processor(tProcessor);
        tArgs.protocolFactory(new TBinaryProtocol.Factory());
        TServer tServer = new TSimpleServer(tArgs);
        tServer.serve();
    }
}
